import request from './request'

/**
 * 获取首页的列表数据
 * import { getProlist } from '@/api'
 * 数据接口参考： http://localhost:3000/apidoc/#api-pro-GetApiPro
 * @param {Object} params 由limit和count组成的对象
 */
export function getProlist (params) {
  // limit和count的默认值 -- 依据接口文档设置
  const data = params || { limit: 10, count: 0 }
  return request({
    url: '/product',
    method: 'get',
    params: data
  })
}

/**
 * 请求首页轮播图数据
 */
export function getBannerlist () {
  return request({
    url: '/banner',
    method: 'get'
  })
}

/**
 * 根据产品的id获取数据
 * @param {Object} params  { proid: '' }
 */
export function getDetailData (params) {
  return request({
    url: '/product/detail',
    method: 'get',
    params
  })
}

/**
 * 注册
 * @param {Object} params { tel: '', password: ''}
 */
export function emailregister (params) {
  return request({
    url: '/user/emailregister',
    method: 'post',
    data: params
  })
}
/**
 * 手机注册登录
 * @param {Object} params { tel: '', md: ''}
 */
export function telRegisterLogin (params) {
  return request({
    url: '/user/telregisterlogin',
    method: 'post',
    data: params
  })
}

/**
 * 手机邮箱登录
 * @param {Object} params { tel: '', md: ''}
 */
export function emlLogin (params) {
  return request({
    url: '/user/emaillogin',
    method: 'post',
    data: params
  })
}

/**
 * 获取验证码
 * @param {Object} params { tel }
 */
export function getCode (params) {
  return request({
    url: '/user/sendCode',
    method: 'get',
    params
  })
}

/**
 * 获取分类接口
 */
export function getCategory () {
  return request({
    url: '/category/getCategory',
    method: 'get'
  })
}
/**
 * 获取分类下送女友礼物窗口
 * @param {Object} params { type }
 */
export function getCategoryGirlfriend (params) {
  return request({
    url: '/category/flower/girlfriend',
    method: 'get',
    params
  })
}
/**
 * 获取分类下送长辈礼物窗口
 * @param {Object} params { type }
 */
export function getCategoryElders (params) {
  return request({
    url: '/category/flower/elders',
    method: 'get',
    params
  })
}

/**
 * 添加地址
 * @param {Object} params { userid, isDefault, name, tel, province, city, county, addressDetail }
 */
export function addAddress (params) {
  return request({
    url: '/address/add',
    method: 'post',
    data: params
  })
}

/**
 * 获取地址列表
 * @param {Object} params { userid }
 */
export function getAddressData (params) {
  return request({
    url: '/address',
    method: 'get',
    params
  })
}

/**
 * 删除地址
 * @param {Object} params { addressid }
 */
export function deleteAddress (params) {
  return request({
    url: '/address/delete',
    method: 'get',
    params
  })
}

/**
 * 获取分类接口
 */
export function getSpecy () {
  return request({
    url: '/specy',
    method: 'get'
  })
}

/**
 * 加入购物车
 * @param {Object} params { userid: '', proid: '', num: 1}
 */
export function addCart (params) {
  return request({
    url: '/cart/add',
    method: 'post',
    data: params
  })
}

/**
 * 查看购物车
 * @param {Object} params { userid: ''}
 */
export function getCartData (params) {
  return request({
    url: '/cart',
    method: 'get',
    params
  })
}

/**
 * 更新购物车
 * @param {Object} params { cartid: '', num: 0 }
 */
export function updateCartData (params) {
  return request({
    url: '/cart/update',
    method: 'get',
    params
  })
}

/**
 * 删除购物车
 * @param {Object} params { cartid: '' }
 */
export function deleteCartData (params) {
  return request({
    url: '/cart/delete',
    method: 'get',
    params
  })
}

/**
 * 添加订单  ---  确认订单
 * @param {Object} params { userid: ''， orderlist: '[{},{}]' }
 */
export function addOrder (params) {
  return request({
    url: '/order/add',
    method: 'post',
    data: params
  })
}

/**
 * 查询  ---  确认订单
 * @param {Object} params { orderid: ''}
 */
export function getOrderData (params) {
  return request({
    url: '/order',
    method: 'get',
    params
  })
}
